package com.fas.system.websocket;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fas.common.constant.Constants;
import com.fas.common.constant.UserConstants;
import com.fas.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PushService {

    @Autowired
    public RedisTemplate<String, String> redisTemplate;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 保存数据至redis数据库
     * @param pushData
     */
    public void sendMsg(PushData pushData){
        String msg = JSONObject.toJSONString(pushData, SerializerFeature.WriteMapNullValue);
        redisTemplate.opsForList().leftPush(Constants.REDIS_PUSH,msg);
    }

    /**
     * 读取数据redis
     * @param
     */
    public String readMsg(){
        return redisTemplate.opsForList().rightPop(Constants.REDIS_PUSH);
    }

    /**
     * 获取所有维保单位用户列表
     * @return
     */
    public List<Integer> getManUserList(){
        return sysUserService.selectUserList(UserConstants.USER_TYPE_MAINTENANCE);
    }
    /**
     * 获取设备所在维保单位的所有用户列表
     * @return
     */
    public List<Integer> getManUserList(String equipmentId){
        return sysUserService.selectUserListByEquipment(UserConstants.USER_TYPE_MAINTENANCE,equipmentId);
    }

    /**
     * 获取工程师单位用户列表
     * @return
     */
    public List<Integer> getEngineerUserList(){
        return sysUserService.selectUserList("01");
    }
}
